package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.CustomerProject;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.CustomerProjectService;

@RestController
@RequestMapping("/customerproject")
public class CustomerProjectController {

    @Autowired
    private CustomerProjectService customerProjectService;

    /**
     * 查询客户购买的护理项目信息
     * @param customerId 客户的唯一标识符
     * @return 包含客户购买护理项目列表的 ResponseBean
     */
    @GetMapping("/projects/{customerId}")
    public ResponseBean<List<CustomerProject>> getCustomerPurchasedProjects(@PathVariable Integer customerId) {
        List<CustomerProject> projects = customerProjectService.getCustomerPurchasedProjects(customerId);
        return new ResponseBean<>(projects);
    }

    /**
     * 续费，更新剩余数量和到期时间
     * @param customerId 客户的唯一标识符
     * @param projectId 护理项目的唯一标识符
     * @param number 更新后的剩余数量
     * @param deadline 更新后的到期时间
     * @return 更新结果的 ResponseBean
     */
    @PutMapping("/renew")
    public ResponseBean<Boolean> updateCustomerProjectConfig(
            @RequestParam Integer customerId,
            @RequestParam Integer projectId,
            @RequestParam Integer number,
            @RequestParam String deadline) {
        boolean result = customerProjectService.updateCustomerProjectConfig(customerId, projectId, number, deadline);
        return new ResponseBean<>(result);
    }

    /**
     * 批量添加客户护理项目
     * @param customerProjects 客户护理项目列表
     * @return 添加结果的 ResponseBean
     */
    @PostMapping("/addBatch")
    public ResponseBean<Boolean> addCustomerProjects(@RequestBody List<CustomerProject> customerProjects) {
        boolean result = customerProjectService.addCustomerProjects(customerProjects);
        return new ResponseBean<>(result);
    }
    /**
     * 根据 customer_id 和 project_id 获取一条 CustomerProject 记录
     * @param customerId 客户的唯一标识符
     * @param projectId 护理项目的唯一标识符
     * @return 包含 CustomerProject 记录的 ResponseBean
     */
    @GetMapping("/project/{customerId}/{projectId}")
    public ResponseBean<CustomerProject> getCustomerProjectByCustomerAndProjectId(
            @PathVariable Integer customerId,
            @PathVariable Integer projectId) {
        CustomerProject project = customerProjectService.getCustomerProjectByCustomerAndProjectId(customerId, projectId);
        return new ResponseBean<>(project);
    }

    /**
     * 根据 customer_id 和 project_id 修改剩余数量
     * @param customerId 客户的唯一标识符
     * @param projectId 护理项目的唯一标识符
     * @param number 更新后的剩余数量
     * @return 更新结果的 ResponseBean
     */
    @PutMapping("/quantity")
    public ResponseBean<Boolean> updateCustomerProjectQuantity(
            @RequestParam Integer customerId,
            @RequestParam Integer projectId,
            @RequestParam Integer number) {
        boolean result = customerProjectService.updateCustomerProjectQuantity(customerId, projectId, number);
        return new ResponseBean<>(result);
    }
}